/**
 * ReportGear(2011)
 */
package com.reportgear.designer.action.file;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;

import javax.swing.JFrame;

import net.abbp.report.context.ReportContext;
import net.abbp.report.model.ReportModel;
import net.abbp.report.view.GridView;
import net.abbp.swing.util.GuiUtils;
import net.abbp.swing.util.ImageUtils;

import com.reportgear.designer.action.ReportAction;
import com.reportgear.report.print.PreviewPane;

/**
 * 打印预览 Action
 * 
 * @version 1.0 2011-4-13
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class PagePreviewAction extends ReportAction {

    private PreviewPane preview = new PreviewPane();

    public PagePreviewAction() {
        setName("预览");
        setMnemonic('V');
        setSmallIcon(ImageUtils.readIcon("file/preview.png"));
    }

    public void actionPerformed(ActionEvent e) {
        JFrame frame = new JFrame();
        frame.setMinimumSize(new Dimension(800, 600));
        frame.setPreferredSize(new Dimension(800, 600));
        frame.setLayout(new BorderLayout());

        GridView worksheet = ReportContext.INSTANCE.getCurrentView();
        ReportModel report = worksheet.getReportModel();

        // 指定默认数据人
        ReportContext.INSTANCE.addBusItem("PersonId", 80382);

        preview.print(report);

        frame.add(preview, BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        GuiUtils.centerWindow(frame);
        frame.setVisible(true);
    }
}